import request from '@/utils/requests.js'

export function list(num) {
  return request({
    url: `/article/list/${num}`,
    method: 'get'
  })
}

export function listAll() {
  return request({
    url: `/article/list/all`,
    method: 'get'
  })
}

export function listPage(id, num) {
  return request({
    url: `/article/list/id/${id}/${num}`,
    method: 'get'
  })
}

// 获取在当前每页条数情况下的总页数
export function getPageCount(num, labelId) {
  if (labelId == undefined) {
    return request({
      url: `/article/count/${num}`,
      method: 'get'
    })
  } else {
    return request({
      url: `/article/count/${num}/${labelId}`,
      method: 'get'
    })
  }
}

// 获取文章最大id
export function getMaxId() {
  return request({
    url: `/article/max`,
    method: 'get'
  })
}

export function getArticleById(articleId) {
  return request({
    method: 'get',
    url: `/article/select/${articleId}`
  })
}

export function getArticleByLabelId(labelId, num) {
  return request({
    url: `/article/list/${labelId}/${num}`,
    method: 'get'
  })
}

export function insert(article) {
  return request({
    url: `/article/insert`,
    method: 'post',
    data: article
  })
}

export function updateOne(article) {
  return request({
    url: `/article/update`,
    method: 'put',
    data: article
  })
}

export function like(articleId) {
  return request({
    url: `/like/incr/${articleId}`,
    method: 'put'
  })
}

export function unlike(articleId) {
  return request({
    url: `/like/decr/${articleId}`,
    method: 'put'
  })
}

export function deleteOne(articleId) {
  return request({
    url: `/article/delete/${articleId}`,
    method: 'delete'
  })
}
